package com.server;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import com.dao.ShopInfo;
import com.dbserver.Condb;

public class ShopListService {
	public ArrayList<ShopInfo> getShop(int type,int orderByDateOrOrder,int pageNum,int pageSize)
	   {   
		ArrayList<ShopInfo> shopList=new ArrayList<ShopInfo>();
		 //处理结果集
	   	Condb condb=new Condb();
	   	int BeginRecord=(pageNum-1)*pageSize;
	    int EndRecord=pageNum*pageSize;
	   	String sql="select * from shopinfo";
	   	if(type!=-1)
	   	{
	   		sql+=" where type="+type;
	   	}
	   	
   		if(orderByDateOrOrder==1)
   		{
   			sql+=" order by createTime desc";
   		}
   		if(orderByDateOrOrder==2)
   		{
   			sql+=" order by createTime asc";
   		}
   		
        if(orderByDateOrOrder==3)
        {
        	sql+=" order by ordersum desc";
        }
        if(orderByDateOrOrder==4){
        	sql+=" order by ordersum asc";
		}
        sql+=" limit "+BeginRecord+","+EndRecord;
	   	ResultSet rs=condb.query(sql);
		try {
			while(rs.next())
			{   
				ShopInfo shopInfo=new ShopInfo();
				shopInfo.setId(rs.getInt("id"));
				shopInfo.setShopId(rs.getString("shopid"));
				shopInfo.setShopName(rs.getString("name"));
				shopInfo.setLocation(rs.getString("location"));
				shopInfo.setXpos(rs.getDouble("xpos"));
				shopInfo.setYpos(rs.getDouble("ypos"));
				shopInfo.setInterf(rs.getString("interf"));
				shopInfo.setTag1(rs.getString("tag1"));
				shopInfo.setTag2(rs.getString("tag2"));
				shopInfo.setCon(rs.getString("con"));
				shopInfo.setStatus(rs.getInt("status"));
				shopInfo.setDescription(rs.getString("description"));
				shopInfo.setBh(rs.getString("bh"));
				shopInfo.setCredit(rs.getInt("credit"));
				shopInfo.setStarsum(rs.getInt("starsum"));
				shopInfo.setOrdersum(rs.getInt("ordersum"));
				shopInfo.setRatesum(rs.getInt("ratesum"));
				shopInfo.setLbs(rs.getInt("lbs"));
				shopInfo.setCreateTimeDate(rs.getDate("createTime"));
				shopList.add(shopInfo);
			}
			rs.close();
			condb.close();
			return shopList;
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		condb.close();
		return null;
	   }
}
